	function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}
var page = 0;
var offset = 0;
var pageSize = 5;
var j=5;


var userid=getCookie("userid");

	function receivedcha(){
		taiochass();
		$.ajax({
			url:"http://localhost:16111/orderform/receivedcha",
			mimeType: "post",
			dataType: "json",
			data:{
				q:0,
				j:j,
				userid:userid
			},
			xhrFields:{withCredentials: true},
			success:function(date){
				console.log(date);
				var str="";
				for(i in date){
					var time=new Date(date[i].undertime);
					var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
					
				str+="<tr class='order-item'>"+
					"<td>"+
						"<label>"+
							"<a href='udai_order_detail.html' class='num'>"+time2 +"订单号:" +date[i].ordernumber +"</a>"+
							"<div class='card'>"+
								"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
								"<div class='name ep2'>"+date[i].comitydescription+"</div>"+
								"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
								"<div class='favour'>使用" +date[i].preferentialinformation + "</div>"+
							"</div>"+
						"</label>"+
					"</td>"+
					"<td>￥"+date[i].comityprices + "</td>"+
					"<td>"+date[i].comitynumber + "</td>"+
					"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
					"<td class='state'>"+
						"<a class='but c6'>" +date[i].orderstatus + "</a>"+
						"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
						"<a href='' class='but c9'>查看物流</a>"+
					"</td>"+
					"<td class='order'>"+
						"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
						"<a href='udai_order_shou.html?id="+date[i].orderid+"' class='but but-primary'>" +date[i].statusbutton + "</a>"+
						
						 "<a href='udai_apply_return.html'  onclick='chuan(\"" + date[i].ordernumber + "\",\"" + date[i].actualpayment + "\")'  class='but c3'>"+date[i].statusbuttonunder+"</a>"+
					"</td>"+
				"</tr>";
				}
				
				document.getElementById("receivedcha").innerHTML = str;
			},
		});
	}
	
	function shochu(ordernumber,actualpayment){
			localStorage.setItem("ordernumber",ordernumber);
			localStorage.setItem("actualpayment",actualpayment);
		}
	
	  
	function shohuochu(){
		var ordernumber =localStorage.getItem("ordernumber");
		var actualpayment =localStorage.getItem("actualpayment");
			$.ajax({
				url:"http://localhost:16111/orderform/receordernumber",
				mimeType: "post",
				dataType: "json",
				data:{
					 ordernumber:ordernumber,
					},
					xhrFields:{withCredentials: true},
				success:function(date){
					var str="";
					for(i in date){					
					str+="<div class='return-item__info'>"+
					"<div class='img' id='picture'>"+
					"<img src='images/1.jpeg'  class='cover'></div>"+
					"<div class='name ep2' id='shoopname'>"+date[i].comitydescription+"</div>"+
					"<div class='type' id='ordercolor'>" +date[i].specifications+ " </div>"+
					"<div class='type' id='ordersieze'>" +date[i].specifications2+ " </div>"+
					"<div class='num' id='ordernumber'>" +ordernumber+"</div>"+
					"</div>";
					document.getElementById("price").innerHTML=actualpayment;
					}
					
					document.getElementById("chuancha").innerHTML = str;
				},
			})
		};
		
		
		function addrece(){
							
							var ordernumber = document.getElementById("ordernumber").innerHTML;
							var servicetype = document.getElementById("servicetype").value;
							var cargostatus = document.getElementById("cargostatus").value;
							var price = document.getElementById("price").innerHTML;
							var refundreason = document.getElementById("refundreason").value;
							var refundinstructions = document.getElementById("refundinstructions").value;
							var shoopname = document.getElementById("shoopname").innerHTML;
							var ordercolor = document.getElementById("ordercolor").innerHTML;
							
							var picture = document.getElementById("picture").innerHTML;
						
							$.ajax({
								method:"post",
								url:"http://localhost:16111/orderform/addrece",
							    dataType: "json",
								data:{ordernumber:ordernumber,servicetype:servicetype,cargostatus:cargostatus,price:price,refundreason:refundreason,refundinstructions:refundinstructions,shoopname:shoopname,ordercolor:ordercolor,picture:picture},
								xhrFields:{withCredentials: true},
								success:function(data)
								{
								
									if(data !="")
									{
										alert("退款成功")
										gai();
									}else
									{
										alert("退款失败")
									}
								}
								})
						}
				
	
	
	
		function taiochass(){
			$.ajax({
			url: "http://localhost:16111/orderform/taiochas",
			mimeType: "post",
			dataType: "json",
			data:{
				userid:userid
			},
			xhrFields:{withCredentials: true},
			success: function(date){
				document.getElementById("articles").innerHTML = date;
			},
			});
		}
		
		
		function shousan(){
			if(offset-pageSize<0){
						alert("没有上一页");
						return;
					}else{
						offset=offset-pageSize;
						page=page+1;
					} 
			var str="";
			$.ajax({
				url: "http://localhost:16111/orderform/fenyecha",
				mimeType: "post",
				dataType: "json",
				data:{
					q:offset,
					j:j,
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success:function(date){
					var str="";
					console.log(date);
					for(i in date){
					var time=new Date(date[i].undertime);
						var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
						var str="";
					str+="<tr class='order-item'>"+
						"<td>"+
							"<label>"+
								"<a href='udai_order_detail.html' class='num'>"+time2 +"订单号:" +date[i].ordernumber +"</a>"+
								"<div class='card'>"+
									"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
									"<div class='name ep2'>"+date[i].comitydescription+"</div>"+
									"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
									"<div class='favour'>使用" +date[i].preferentialinformation + "</div>"+
								"</div>"+
							"</label>"+
						"</td>"+
						"<td>￥"+date[i].comityprices + "</td>"+
						"<td>"+date[i].comitynumber + "</td>"+
						"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
						"<td class='state'>"+
							"<a class='but c6'>" +date[i].orderstatus + "</a>"+
							"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
							"<a href='' class='but c9'>查看物流</a>"+
						"</td>"+
						"<td class='order'>"+
							"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
							"<a href='udai_order_shou.html?id="+date[i].orderid+"' class='but but-primary'>" +date[i].statusbutton + "</a>"+
							"<a onclick='xiu("+date[i].ordernumber+")' class='but c3'>退货退款</a>"+
						"</td>"+
					"</tr>";
					}
					
					document.getElementById("receivedcha").innerHTML = str;
				},
			})
		}
		
		
		function shouxiao(){
			if(page==2){
							alert("没有下一页");
							return;
						}else{
							offset=offset+pageSize;
							page=page-1;
						} 
			$.ajax({
				url: "http://localhost:16111/orderform/fenyecha",
				mimeType: "post",
				dataType: "json",
				data:{
					q:offset,
					j:j,
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success:function(date){
					
					var str="";
					for(i in date){
					var time=new Date(date[i].undertime);
						var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
						var str="";
					str+="<tr class='order-item'>"+
						"<td>"+
							"<label>"+
								"<a href='udai_order_detail.html' class='num'>"+time2 +"订单号:" +date[i].ordernumber +"</a>"+
								"<div class='card'>"+
									"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
									"<div class='name ep2'>"+date[i].comitydescription+"</div>"+
									"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
									"<div class='favour'>使用" +date[i].preferentialinformation + "</div>"+
								"</div>"+
							"</label>"+
						"</td>"+
						"<td>￥"+date[i].comityprices + "</td>"+
						"<td>"+date[i].comitynumber + "</td>"+
						"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
						"<td class='state'>"+
							"<a class='but c6'>" +date[i].orderstatus + "</a>"+
							"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
							"<a href='' class='but c9'>查看物流</a>"+
						"</td>"+
						"<td class='order'>"+
							"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
							"<a href='udai_order_shou.html?id="+date[i].orderid+"' class='but but-primary'>" +date[i].statusbutton + "</a>"+
							"<a onclick='xiu("+date[i].ordernumber+")' class='but c3'>退货退款</a>"+
						"</td>"+
					"</tr>";
					}
					
					document.getElementById("receivedcha").innerHTML = str;
				},
				
			})
		}
		
		
		
		
		
		function gai(){
			var arr =localStorage.getItem("ordernumber");
			var reason=document.getElementById("reason").value;
			$.ajax({
			url: "http://localhost:16111/orderform/tuikuangs",
			method: "post",
			dataType: "json",
			 data:{
				 ordernumber:arr,reason:reason
				},
				xhrFields:{withCredentials: true},
					success: function(data) {
					alert("修改成功");
					
				},
						error: function(text) {
							var json = eval(text);
							alert(text.toString()+"111");
							
						}
					})
					}
		
		//查询退款订单
		function requestData(){
					  $.ajax({
			          url: "http://localhost:16111/orderform/tuikuanchas",
			          type: "post",
			          dataType: "json",
					  data:{
						  userid:userid
					  },
					  xhrFields:{withCredentials: true},
			          success: function(data){
			              /*这个方法里是ajax发送请求成功之后执行的代码*/
			              showData(data);//我们仅做数据展示
			          },
			         error: function(msg){
			             alert("ajax连接异常："+msg);
			        }
			     });
			 }
			 
				function showData(data) {
					// var time=new Date(date[i].undertime);
					// var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
					
			     var str = "";//定义用于拼接的字符串
				 
			      for (var i = 0; i < data.length; i++) {
					  var time=new Date(data[i].orderupdatetime);
					  var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
			          //拼接表格的行和列
			          str = "<tr><td>" + data[i].ordernumber + "</td><td>" + data[i].ordernumber + "</td><td>" + data[i].comitydescription + "</td><td>" +time2+ "</td><td>" + data[i].actualpayment + "</td><td>" + data[i].orderstatus + "</td><td>" + data[i].orderstatus + "</td></tr>";
			          //追加到table中
			          $("#tab").append(str);
							   }
					}